package com.chen.mapper;

import com.chen.popj.entity.ContestCodeSubmit;
import com.chen.popj.vo.ContestVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ContestCodeSubmitMapper {

    /**
     * 创建一个比赛提交记录
     *
     * @param contestCodeSubmit
     */
    void save(ContestCodeSubmit contestCodeSubmit);

    /**
     * 根据题目提交id获取比赛提交记录
     *
     * @param problemSubmitId
     * @return
     */
    @Select("select * from contest_code_submit where problem_submit_id = #{problemSubmitId};")
    ContestCodeSubmit getByProblemSubmitId(Integer problemSubmitId);

    /**
     * 根据id修改比赛代码提交信息
     *
     * @param contestCodeSubmitUpdate
     */
    void update(ContestCodeSubmit contestCodeSubmitUpdate);

    @Select("select result from contest_code_submit where " +
            "user_id = #{userId} and problem_id = #{problemId} and contest_id = #{contestId} " +
            "order by submit_time limit 1")
    String getContestCodeSubmitResult(Integer userId, Integer problemId, Integer contestId);
}
